#!/bin/bash

base="/Users/eports/Desktop/111"
date=$(date +%Y%m%d)
hour=$(date +%H)
time=$(date +%H%M%S)

charset="UTF8"
username="root"
password="123456"
database="eports_dev"
database1="portal_ms"
filename="$database.$date$time.sql"
filename1="$database1.$date$time.sql"

cd $base

if [ ! -d $date ]
then
mkdir ./$date
fi

dir="./$date/$date$hour"
if [ ! -d $dir ]
then
mkdir $dir
fi

path="$base/$dir"

/usr/local/var/homebrew/linked/mariadb/bin/mysqldump -u$username -p$password --opt --default-character-set=$charset -q $database > $path/$filename
/usr/local/var/homebrew/linked/mariadb/bin/mysqldump -u$username -p$password --opt --default-character-set=$charset -q $database1 > $path/$filename1

cd $path
tar zcf ./$filename.tar.gz ./$filename
rm -r ./$filename

tar zcf ./$filename1.tar.gz ./$filename1
rm -r ./$filename1